fix(anthropic): handle plain string in part_to_message_block#5571
fix(anthropic): handle plain string in part_to_message_block#5571AliMuhammadAslam wants to merge 4 commits intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Response from ADK Triaging Agent Hello @AliMuhammadAslam, thank you for your contribution! Before we can merge this PR, you need to sign the Contributor License Agreement (CLA). It seems that the CLA check has failed. For more details, please review our contribution guidelines. Thank you! |
|
I have signed the CLA. |
When a tool returns a response where the "content" key holds a plain string, part_to_message_block() was iterating over it directly. Since strings are iterable in Python, the loop produced one character per iteration instead of the full text. LoadSkillResourceTool is a concrete case: it returns a response dict with a "content" key that is a string, not a list. The fix adds an isinstance check before the loop. When content is a string it is used directly. When it is a list, the existing join logic runs unchanged. A unit test covers both paths. Fixes google#5358
|
Hi @AliMuhammadAslam , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share. |
|
Hi @Jacksunwei , can you please review this. |
Problem
part_to_message_block()inanthropic_llm.pyiterates overresponse_data["content"]without checking whether the value is a list or a plain string. When a tool returns a response wherecontentis a string, the loop yields one character per iteration, so the assembled result is individual characters joined by newlines instead of the full text.LoadSkillResourceToolis a concrete example: it returns{"skill_name": ..., "file_path": ..., "content": "<file text>"}wherecontentis a string, not a list.Closes #5358
Fix
Added an
isinstance(response_data["content"], str)check before the loop. Whencontentis a string it is passed through directly. When it is a list, the existing item-by-item join logic runs as before.Testing
Added
test_part_to_message_block_with_string_contenttotests/unittests/models/test_anthropic_llm.py. The test creates a function response matching theLoadSkillResourceToolshape and asserts the full string comes through unchanged.All existing
part_to_message_blocktests continue to pass.